%%%% Load analysis include load torque and system inertia %%%%
function [Th, Tk, Jh, Jk] = load_analysis(the1, the2)
g = 9.79;   % Local acceleration of gravity.
Jr0=53.8e-7;  % EC40 rotor inertia

KH = 420;   % Exoskeleton hip reduction ratio KH = 126*3.3333=420
m1 = 3.5+5;   % Exoskeleton thigh mass without man, unit:kg
l1 = 0.35;   % Exoskeleton thigh length(1.75m), unit:m
lc1 = 0.5*l1;   % Centroid is at the center of thigh assumed that thigh link is uniform.

KK = 270;   % Exoskeleton knee reduction ratio KH = 81*3.3333=270
m2 = 3+5;     % Exoskeleton shank mass without man, unit:kg
l2 = 0.3;   % Exoskeleton shank length(1.75m), unit:m
lc2 = 0.5*l2;   % Centroid is at the center of thigh assumed that thigh link is uniform.

% Hip load torque
Th = m1*g*lc1*abs(sin(the1)) + m2*g*abs( l1*sin(the1)-lc2*sin(-the2-the1) );
Th = Th / KH;   % Convert to rotor

% Knee load torque
Tk = m2*g*lc2*abs( sin(-the2-the1) );
Tk = Tk / KK;   % Convert to rotor

% Hip system inertia
Jh = 1/3*m1*l1*l1 + 1/3*m2*l2*l2 + m2*l1*l1 + m2*l1*l2*cos(the2);
Jh = Jh / (KH*KH);  % Convert to rotor

% Knee system inertia
Jk = 1/3*m2*l2*l2;
Jk = Jk / (KK*KK);  % Convert to rotor

end
